////////////////////////////////////////////////
// MACHINE GENERATED, PLEASE DONOT MODIFY!    //
////////////////////////////////////////////////

#include <unordered_map>
#include <fstream>
#include <vector>
#include "msg_dispatcher.hh"
#include "../common/generated_message_id_defines.hh"
#include "../../corelib/util/string_util.hh"

bool MsgDispatcher::start(const std::string& cfgPath) {
    std::ifstream file;
    file.open(cfgPath.c_str(), std::ios::in);
    if (file.is_open()) {
        std::string line;
        while (std::getline(file, line)) {
            std::vector<std::string> result;
            kratos::corelib::StringUtil::split(line, ",", result);
            if (result.size() == 2) {
                msgSiteMap_[std::stoul(result[0])] = static_cast<std::uint16_t>(std::stoul(result[1]));
            }
        }
    } else {
        return false;
    }
    file.close();
    return true;
}

std::uint16_t MsgDispatcher::getSiteType(std::uint32_t msgID) {
    auto it = msgSiteMap_.find(msgID);
    if (it == msgSiteMap_.end()) {
        return 0;
    }
    return it->second;
}

